package com.moshang.blog.core.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author xww
 * @Description //TODO
 * @Date 2019/7/23   9:59
 **/
public final class WebThreadLocalUtils {

    private static ThreadLocal<HttpServletRequest> request = new ThreadLocal();

    public WebThreadLocalUtils() {
    }

    public static void setRequest(HttpServletRequest value) {
        request.set(value);
    }

    public static void clear() {
        request.remove();
    }

    public static Object getAttrbitue(String name) {
        return ((HttpServletRequest)request.get()).getAttribute(name);
    }

    public static String getParameter(String name) {
        return ((HttpServletRequest)request.get()).getParameter(name);
    }

    public static void setAttrbitue(String name, Object value) {
        ((HttpServletRequest)request.get()).setAttribute(name, value);
    }

    public static void removeAttrbitue(String name) {
        ((HttpServletRequest)request.get()).removeAttribute(name);
    }

    public static Object getSessionAttrbitue(String name) {
        return ((HttpServletRequest)request.get()).getSession().getAttribute(name);
    }

    public static void setSessionAttrbitue(String name, Object value) {
        ((HttpServletRequest)request.get()).getSession().setAttribute(name, value);
    }

    public static void removeSessionAttrbitue(String name) {
        ((HttpServletRequest)request.get()).getSession().removeAttribute(name);
    }

    public static final HttpServletRequest getRequest() {
        return (HttpServletRequest)request.get();
    }
}
